<?php

namespace common\models;

use common\components\active\ActiveRecord;
use Yii;

/**
 * This is the model class for table "proposer".
 *
 * @property int            $proposer_id
 * @property int            $proposer_enterprise_case_id 申请方
 * @property string         $proposer_enterprise_name    企业名称
 * @property string         $proposer_corporation        法人代表
 * @property string         $proposer_person             联系人
 * @property int            $proposer_type               申请人type
 * @property string         $proposer_phone              联系人
 * @property string         $proposer_email              联系邮箱
 * @property string         $proposer_address            联系地址
 *
 * @property EnterpriseCase $proposerEnterpriseCase
 */
class Proposer extends ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'proposer';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [
                [
                    'proposer_enterprise_case_id',
                    'proposer_enterprise_name',
                    'proposer_corporation',
                    'proposer_person',
                    'proposer_phone',
                    'proposer_email',
                    'proposer_address'
                ],
                'required'
            ],
            [['proposer_enterprise_case_id', 'proposer_type'], 'integer'],
            [['proposer_enterprise_name'], 'string', 'max' => 64],
            [['proposer_corporation', 'proposer_email'], 'string', 'max' => 45],
            [['proposer_person', 'proposer_phone'], 'string', 'max' => 20],
            [['proposer_address'], 'string', 'max' => 255],
            [['proposer_enterprise_case_id'], 'unique'],
            [
                ['proposer_enterprise_case_id'],
                'exist',
                'skipOnError'     => true,
                'targetClass'     => EnterpriseCase::className(),
                'targetAttribute' => ['proposer_enterprise_case_id' => 'enterprise_case_id']
            ],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'proposer_id'                 => 'Proposer ID',
            'proposer_enterprise_case_id' => '申请方',
            'proposer_enterprise_name'    => '企业名称',
            'proposer_corporation'        => '法人代表',
            'proposer_person'             => '联系人',
            'proposer_type'               => '申请人type',
            'proposer_phone'              => '联系人',
            'proposer_email'              => '联系邮箱',
            'proposer_address'            => '联系地址',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getProposerEnterpriseCase()
    {
        return $this->hasOne(EnterpriseCase::className(), ['enterprise_case_id' => 'proposer_enterprise_case_id']);
    }
}
